package cn.com.shaom.learning.sb.web.jsp;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.Map;

/**
 * @author Shaom
 */
@Controller
public class WelcomeController {

    @Value("${application.message:Hello World}")
    private String message;

    @GetMapping("/index")
    public ModelAndView welcome(Model model) {
        model.addAttribute("time", new Date());
        model.addAttribute("message", this.message);
        return new ModelAndView("index");
    }

    @RequestMapping("/foo")
    public String foo(Map<String, Object> model) {
        throw new RuntimeException("Foo");
    }

}